package com.vote.thrift.test;

import java.util.List;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

import com.vote.thrift.utils.CommentUtils;
import com.vote.thrift.utils.TComment;

public class Client {
	public static void main(String[] args) {
		TTransport transport = new TSocket("localhost", 9092);
		TProtocol protocol = new TBinaryProtocol(transport);
		CommentUtils.Client client = new CommentUtils.Client(protocol);
		try {
			transport.open();
			TComment tc = new TComment();
			long allstart = System.currentTimeMillis();
			for(int i = 0; i < 2; i++){
				long lstart = System.currentTimeMillis();
				for(int j = 0; j < 1; j++){
//					tc.setCommentText("test " + i + " " + j);
//					tc.setCommentTime(System.currentTimeMillis());
//					tc.setFromUserId(j);
//					tc.setToUserId(i);
//					tc.setQuestionnaireId(10000+j);
//					
//					client.insertComment(tc);
					List<TComment> ls = client.getCommentListByQuestionnaireId(10000+j, 0, 0);
				}
				System.out.println("loop " + i + " finish!");
				long lend = System.currentTimeMillis();
				System.out.println("insert loop "+i+" use " + (float)(((float)(lend - lstart))/((float)1000)) + "s");
			}
			long allend = System.currentTimeMillis();
			
			System.out.println("insert all use " + (float)(((float)(allend - allstart))/((float)1000)) + "s");
//			List<TComment> ls = client.getCommentListByQuestionnaireId(15, 0, 0);
//			
//			int count = client.getCommentListCountByQuestionnaireId(15);
//			System.out.println("comment count = " + count);
//			
//			for(TComment ttc : ls){
//				System.out.println("ToUserId = " + ttc.getToUserId());
//				System.out.println("FromUserId = " + ttc.getFromUserId());
//				System.out.println("QuestionnaireId = " + ttc.getQuestionnaireId());
//				System.out.println("CommentTime = " + ttc.getCommentTime());
//				System.out.println("CommentText = " + ttc.getCommentText());
//				System.out.println("");
//			}
//			
			transport.flush();
			transport.close();
			
		} catch (TTransportException e) {
			e.printStackTrace();
		} catch (TException e) {
			e.printStackTrace();
		}
		
	}
}
